package com.leyou.item.api;

import com.leyou.common.pojo.PageResult;
import com.leyou.item.pojo.Brand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@RequestMapping("/brand")
public interface BrandApi {

    /**
     * 根据查询条件分页并排序查询品牌信息
     * @param key 搜索关键词
     * @param page 页码
     * @param rows 分页条数
     * @param sortBy 排序字段
     * @param desc 是否升序
     * @return
     */
    @GetMapping("/page")
    public PageResult<Brand> queryBrandsByPage(
            @RequestParam(value = "key",required = false)String key,
            @RequestParam(value = "page",defaultValue = "1")Integer page,
            @RequestParam(value = "rows",defaultValue = "5")Integer rows,
            @RequestParam(value = "sortBy",required = false)String sortBy,
            @RequestParam(value = "desc",required = false)Boolean desc
    );

    /**
     * 新增品牌
     * @param brand
     * @param cids
     */
    @RequestMapping
    public Void saveBrand(Brand brand, @RequestParam("cids")List<Long> cids);

    /**
     * 根据品牌id删除品牌以及对应的中间表数据
     * @param id
     * @return
     */
    @GetMapping("/delBrand/{id}")
    public Void delBrand(@PathVariable("id") Long id);
    /**
     * 根据分类id查询品牌列表
     * @param cid
     * @return
     */
    @GetMapping("/cid/{cid}")
    public List<Brand> queryBrandsByCid(@PathVariable("cid")Long cid);
    /**
     * 根据品牌id查询品牌
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Brand queryBrandById(@PathVariable("id")Long id);
}
